package com.eascs.accessory.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.eascs.accessory.entity.Accessory;
import com.eascs.accessory.service.AccessoryService;
import com.eascs.datalist.entity.O2oDataListEntity;
import com.eascs.site.view.ViewContext;
import com.eascs.workflow.common.vo.ModelResult;
/**
 * 空白合同跳转下载
 * @author ycz
 *
 */
@Controller
@RequestMapping(value = "/ty")
public class AccessoryContractController{
	@Inject
	AccessoryService accessoryService;

	/**
	 * 
	 * @Title: interview
	 * @Description:空白合同跳转到业务指引下载合同
	 * @author user
	 * @return
	 * @return String
	 * @throws @date
	 * 2016年8月9日 下午3:56:00/accessory/help/interview
	 */
	@RequestMapping(value = "/help/interview", method = RequestMethod.GET)
	public String toContract(String resourceCode,@RequestParam(value="master",required=false) String master) {
		if(master == null){
			ViewContext.put("masterType","master-loan");
		}else{
			ViewContext.put("masterType",master);
		}

		if(("customerManage").equals(resourceCode)){
			ViewContext.put("accessoryTitle","面签指引");
		}else if(("loanManage").equals(resourceCode)){
			ViewContext.put("accessoryTitle","业务指引");
		}else if(("approvalManage").equals(resourceCode)){
			ViewContext.put("accessoryTitle","有问必答");
		}else if(("operationalGuidelines").equals(resourceCode)){
			ViewContext.put("accessoryTitle","业务发文");
		}
		
		//指引分类
				Accessory accessory=accessoryService.findAccessoryByResourceCode(resourceCode);
				List<O2oDataListEntity> accessoryattachs= accessoryService.findFileByAccessroyId(accessory.getId());
				accessory.setSubDataListEntity(accessoryattachs);
				ViewContext.put("accessory", accessory);
				//一级标题
				ModelResult<List<Accessory>> levelOneResult=accessoryService.findNodeByParentId(accessory.getId());
				List<Accessory> levelOneList=levelOneResult.getModel();
				for(Accessory levelOne : levelOneList){
					//一级附件
					List<O2oDataListEntity> levelOneattachs= accessoryService.findFileByAccessroyId(levelOne.getId());
					levelOne.setSubDataListEntity(levelOneattachs);
				}
				
				
				for (Accessory levelOne : levelOneList) {
					//二级标题
					ModelResult<List<Accessory>> levelTwoResult=accessoryService.findNodeByParentId(levelOne.getId());
					List<Accessory> levelTwoList=levelTwoResult.getModel();
					
					levelOne.setSubResources(levelTwoList);
					
					for(Accessory levelTwo : levelTwoList){
						//二级附件
						List<O2oDataListEntity> levelTwoattachs= accessoryService.findFileByAccessroyId(levelTwo.getId());
						levelTwo.setSubDataListEntity(levelTwoattachs);
					}
				}
		ViewContext.put("accessoryViews", levelOneList);
		
		return "/help/interview";
	}
	
}
